﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <title>铸造1_2线数据</title>
</head>
<body class="container">
<div class="row">
    <div class="col-sm-6"><h4><span id="date">{{ date }}</span></h4></div>
</div>
<div class="row">
    <div class="col-lg-6 col-md-6, col-sm-12">
        <table class="table table-condensed">
            <caption><h4><span class="label label-info">工厂1</span></h4></caption>
            <tr>
                <th>工序</th>
                <th>白班</th>
                <th>夜班</th>
                <th>总数</th>
            </tr>
            <tr>
                <td><h4><a class="label label-primary" href="/pos/铸造1线/day/0/factory/1">铸造1线</a></h4></td>
                <td><h4><span id="qm_11" class="text-muted">{{ zz_1_1[0] }}</span><br/><span
                        id="zz_1_1">{{ zz_1[0] }}</span>
                </h4>
                </td>
                <td><h4><span id="qm_12" class="text-muted">{{ zz_1_1[1] }}</span><br/><span
                        id="zz_1_2">{{ zz_1[1] }}</span>
                </h4>
                </td>
                <td><h4><span id="qm_10" class="text-muted">{{ zz_1_1[2] }}</span><br/><span
                        id="zz_1">{{ zz_1[2] }}</span>
                </h4>
                </td>
            </tr>
            {# F1旋压1 #}
            <tr>
                <td><h4><a class="label label-primary" href="/pos/铸造2线_东/day/0/factory/1">铸造2线_东</a></h4></td>
                <td><h4><span id="xy_11" class="text-muted">{{ zz_2_e_1[0] }}</span><br/><span
                        id="zz_2_e_1">{{ zz_2_e[0] }}</span>
                </h4>
                </td>
                <td><h4><span id="xy_12" class="text-muted">{{ zz_2_e_1[1] }}</span><br/><span
                        id="zz_2_e_2">{{ zz_2_e[1] }}</span>
                </h4>
                </td>
                <td><h4><span id="xy_10" class="text-muted">{{ zz_2_e_1[2] }}</span><br/><span
                        id="zz_2_e">{{ zz_2_e[2] }}</span>
                </h4>
                </td>
            </tr>
            {# F1旋压2 #}
            <tr>
                <td><h4><a class="label label-primary" href="/pos/铸造2线_边浇/day/0/factory/1">铸造2线 边浇</a></h4></td>
                <td><h4><span id="xy_11" class="text-muted">{{ zz_2_b_1[0] }}</span><br/><span
                        id="zz_2_b_1">{{ zz_2_b[0] }}</span>
                </h4>
                </td>
                <td><h4><span id="xy_12" class="text-muted">{{ zz_2_b_1[1] }}</span><br/><span
                        id="zz_2_b_2">{{ zz_2_b[1] }}</span>
                </h4>
                </td>
                <td><h4><span id="xy_10" class="text-muted">{{ zz_2_b_1[2] }}</span><br/><span id="zz_2_b">{{ zz_2_b[2] }}</span>
                </h4>
                </td>
            </tr>

        </table>
    </div>
    {#    <button id="emit">发射</button>#}
</div>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/js/socket.min.io.js"></script>
<script type="text/javascript">
    $("document").ready(function () {
        $("#btn_jg").click(function () {
            socket.emit("evt_detail", {type: $("#btn_jg").val()});
        });
        $("#emit").click(function () {
            socket.emit("evt_index", {factory: 2, xy: 1000, jg: 2000});
            {#console.log({factory: 2, xy: 1000, jg: 2000});#}
        });

        let socket = io.connect('http://' + document.domain + ':' + location.port);
        socket.on('zz_data', function (data) {
            console.log(data);
            // 循环
            let prefix = '#'; //工厂前缀
            for (let item in data) {
                let new_num;
                if (data.hasOwnProperty(item))
                    new_num = data[item];
                else
                    continue;
                // 更新不同的工厂数据
                if (data['factory'] === 2)
                    prefix = '#f2_';
                else
                    prefix = '#';
                {#console.log('后缀：' + prefix);#}

                // 页面元素不存在，skip
                if ($(prefix + item).length <= 0) {
                    {#console.log('忽略：' + prefix + item);#}
                    continue;
                }
                // 更新 总数
                $(prefix + item).html(new_num);
                // 更新 白班/夜班
                {#console.log(`是白班?${data['is_daytime']}`);#}
                if (typeof(data['is_daytime']) !== 'undefined' && data['is_daytime']) {
                    $(prefix + item + '_1').html(new_num);
                } else {
                    let v_daytime = parseInt($(prefix + item + '_1').html());
                    // 强制刷新
                    if (v_daytime < 0) {
                        location.reload(true);
                    }
                    $(prefix + item + '_2').html(new_num - v_daytime);
                }  // 夜班
            }
        });

        socket.on("refresh", function (data) {
            if (data)
                {#$(location).attr('href', '/');#}
                location.reload(true);
        });
    });
</script>
</body>
</html>